﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Package_Jeu;
using System.Runtime.Serialization.Formatters.Binary;

namespace CivilisationIHM
{
    /// <summary>
    /// Logique d'interaction pour MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            
            String chemin = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"..\..\..\Images\";
            Uri iconUri = new Uri(chemin + "king.ico");
            this.Icon = BitmapFrame.Create(iconUri);
        }

        private void NouvellePartie(object sender, RoutedEventArgs e)
        {
            Menu menu = new Menu();
            App.Current.MainWindow = menu;
            this.Close();
            menu.Show();
        }

        private void Quitter(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void ChargerPartie(object sender, RoutedEventArgs e)
        {
        
            Partie engine;
            BinaryFormatter serialiser = new BinaryFormatter();
            try
            {
                System.IO.FileStream fichier = System.IO.File.Open("pierreLorilleux.test", System.IO.FileMode.Open);
                engine = serialiser.Deserialize(fichier) as Partie;
                fichier.Close();
                CarteIHM carte = new CarteIHM(engine);
                App.Current.MainWindow = carte;
                this.Close();
                carte.Show();
            }
            catch (System.IO.FileNotFoundException)
            {
                MessageBox.Show("Pas de sauvegarde disponible");
                }
        }
    }
}
